﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class RedProp : MonoBehaviour, IRedProp
{
    [SerializeField]
    public UISprite redImg;

    [SerializeField]
    public SystemNofityType msgType;


    public void Awake() 
    {
        if (redImg == null)
            redImg = GetComponent<UISprite>();

        //问一下是否通知
        //RedNewMsgNotifiy.I.AddRedProps(msgType, (IRedProp)this);



        if (RedNewMsgNotifiy.I.IsMsg(msgType))
        {
            ShowRedProp(true);
        }
        else 
        {
            redImg.gameObject.SetActive(false);
        }

        EventManager.Instance.register(EventManager.EventType.ET_ShowRedMsg, Display);

    }

    private void Display(params object [] args) 
    {
        SystemNofityType type = (SystemNofityType)args[0];
        bool display = (bool)args[1];

        if ((msgType & type) > 0) 
        {
            redImg.gameObject.SetActive(display);
        }
      
    }


    public void ShowRedProp(bool isShow)
    {
        if (redImg != null)
            redImg.gameObject.SetActive(isShow);
    }

    public void OnDestroy() 
    {
        EventManager.Instance.unregister(EventManager.EventType.ET_ShowRedMsg, Display);
    }   

}
public interface IRedProp 
{
    void ShowRedProp(bool isShow);
}

